# import numpy as np
# from scipy.ndimage import rotate
# import matplotlib.pyplot as plt
#
# # 假设你的多波段数据是通过 np.load 加载的
# def load_multiband_data(file_path):
#     return np.load(file_path)  # 读取 npy 文件
#
# # 对多波段影像进行旋转
# def rotate_multiband_image(bands, angle):
#     rotated_bands = []
#     for band in bands:
#         # 使用 scipy.ndimage.rotate 进行图像旋转
#         rotated_band = rotate(band, angle, reshape=True, mode='nearest', order=1)
#         rotated_bands.append(rotated_band)
#     return np.array(rotated_bands)
#
# # 显示某个波段图像
# def display_band_image(band):
#     plt.imshow(band, cmap='gray')
#     plt.colorbar()
#     plt.title("Rotated Band")
#     plt.show()
#
# # 主程序
# def main():
#     # 加载多波段影像数据
#     input_file = 'data/image/28.npy'  # 输入数据文件路径
#     bands = load_multiband_data(input_file)
#
#     # 设置旋转角度
#     angle = 135  # 旋转角度（可以根据需求修改）
#
#     # 进行旋转处理
#     rotated_bands = rotate_multiband_image(bands, angle)
#
#     # 可选：显示旋转后的某个波段图像
#     display_band_image(rotated_bands[0])  # 显示第一个波段（可根据需求选择波段）
#
# if __name__ == "__main__":
#     main()
import os

import numpy as np
from matplotlib import pyplot as plt
def compute_color_difference(img1, img2):
    # 确保图像形状相同
    if img1.shape != img2.shape:
        raise ValueError("Input images must have the same shape.")

    # 计算色差（欧几里得距离）
    color_diff = np.sqrt(np.sum((img1 - img2) ** 2, axis=-1))  # 计算每个像素的色差
    return color_diff
from rs_trasformer import Compose,RandomSplicing
name='28.npy'# md随便选了几张结果连分割图都没有，倒霉
x1=r'data\image'
x2=r'data\edge'
x3=r'data\mask'
input=os.path.join(x1,name)#4波段数据
edge=os.path.join(x2,name) #边缘线分割图
mask=os.path.join(x3,name) #地块分割图

transformers=Compose([
        RandomSplicing(prob=0.1, direction='Horizontal', band_num=4)
     ] #填充的颜色
)
x=transformers(input,edge,mask)
#
# plt.imshow(x[0])  # 显示第一个图像
# plt.colorbar()  # 显示颜色条
# plt.show()
input1=np.load(input)
input1=input1.transpose(1,2,0)
input2=x[0]
rgb_image1 = input2[:, :,:3]  # 选择前三个波段（R, G, B）
rgb_image2= input1[:, :,:3]
rgb_image1 = rgb_image1.astype(np.float32)  # 转换为float类型
rgb_image2 = rgb_image2.astype(np.float32)  # 转换为float类型
if np.max(rgb_image1) > 1:
    rgb_image1 /= 255.0  # 如果数据在[0, 255]范围内，归一化到[0, 1]
if np.max(rgb_image2) > 1:
    rgb_image2 /= 255.0  # 如果数据在[0, 255]范围内，归一化到[0, 1]
# 打印形状以确认
print("RGB Image Shape:", rgb_image1.shape)
print("RGB Image Shape:", rgb_image2.shape)
# 显示RGB图像
# 创建子图，显示两个RGB图像
fig, axes = plt.subplots(1, 2, figsize=(12, 6))  # 1行2列的子图
axes[0].imshow(rgb_image1)
axes[0].axis('off')  # 关闭坐标轴
axes[0].set_title('RGB Image 1')
axes[1].imshow(rgb_image2)
axes[1].axis('off')  # 关闭坐标轴
axes[1].set_title('RGB Image 2')
plt.tight_layout()
plt.show()
# 计算色差
color_difference = compute_color_difference(rgb_image1, rgb_image2)
# 显示色差图像
plt.imshow(color_difference, cmap='hot')  # 使用热图显示色差
plt.axis('off')
plt.title('Color Difference')
plt.colorbar(label='Difference')
plt.show()
